package com.techstar.ats.dxp.live;

import java.time.LocalDateTime;
import java.util.Objects;

import com.techstar.ats.dxp.CsvFormatter;
import com.techstar.ats.type.DeviceType;
import com.techstar.ats.type.TrainMode;

public class TrainIndication implements CsvFormatter {
	private static final long serialVersionUID = 1L;
	public int rtu;
	public int mmccWin;
	public int mmccWinOffset;
	public DeviceType devType;
	public String devName;
	public String trainIdx;
	public String group;
	public String train;
	public String global;
	public String dest;
	public int rollingstock;
	public String driver;
	public boolean hasRoute = false;
	public Integer route;
	public int optTime;
	public int mode;
	public LocalDateTime arriveTime;
	public LocalDateTime departTime;
	public int rate;
	public int speed;

	public boolean toCsvString(StringBuffer sb) {
		sb.append(this.rtu)
			.append(',')
			.append(this.mmccWin)
			.append(',')
			.append(this.mmccWinOffset)
			.append(',')
			.append(this.devType)
			.append(',')
			.append(this.devName)
			.append(',')
			.append(this.trainIdx)
			.append(',')
			.append(this.group)
			.append(',')
			.append(this.train)
			.append(',')
			.append(this.global)
			.append(',')
			.append(this.dest)
			.append(',')
			.append(this.rollingstock)
			.append(',')
			.append(this.driver)
			.append(',')
			.append(this.route)
			.append(',')
			.append(this.optTime)
			.append(',')
			.append(this.toSetString(TrainMode.valueOf(this.mode)))
			.append(',');
		if(!Objects.isNull(this.arriveTime)) {
			sb.append(this.arriveTime.format(DATE_TIME_FORMATTER));
		}

		sb.append(',');
		if(!Objects.isNull(this.departTime)) {
			sb.append(this.departTime.format(DATE_TIME_FORMATTER));
		}

		sb.append(',')
			.append(this.rate)
			.append(',')
			.append(this.speed);
		return true;
	}
}
